<!DOCTYPE html>
<html lang="zh-cmn-Hans-CN">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>BaseHangul在线编解码器 Online BaseHangul Encoder And Decoder</title>
  <link rel="stylesheet" href="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-9999-y/pure/2.0.6/pure-min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/sugina-dev/cdn@20200716/pandoc.css">
<script>
// https://github.com/basehangul/basehangul-javascript/blob/master/basehangul.js

var ksx1001_1028 = '가각간갇갈갉갊감갑값갓갔강갖갗같갚갛개객갠갤갬갭갯갰갱갸갹갼걀걋걍걔걘걜거걱건걷걸걺검겁것겄겅겆겉겊겋게겐겔겜겝겟겠겡겨격겪견겯결겸겹겻겼경곁계곈곌곕곗고곡곤곧골곪곬곯곰곱곳공곶과곽관괄괆괌괍괏광괘괜괠괩괬괭괴괵괸괼굄굅굇굉교굔굘굡굣구국군굳굴굵굶굻굼굽굿궁궂궈궉권궐궜궝궤궷귀귁귄귈귐귑귓규균귤그극근귿글긁금급긋긍긔기긱긴긷길긺김깁깃깅깆깊까깍깎깐깔깖깜깝깟깠깡깥깨깩깬깰깸깹깻깼깽꺄꺅꺌꺼꺽꺾껀껄껌껍껏껐껑께껙껜껨껫껭껴껸껼꼇꼈꼍꼐꼬꼭꼰꼲꼴꼼꼽꼿꽁꽂꽃꽈꽉꽐꽜꽝꽤꽥꽹꾀꾄꾈꾐꾑꾕꾜꾸꾹꾼꿀꿇꿈꿉꿋꿍꿎꿔꿜꿨꿩꿰꿱꿴꿸뀀뀁뀄뀌뀐뀔뀜뀝뀨끄끅끈끊끌끎끓끔끕끗끙끝끼끽낀낄낌낍낏낑나낙낚난낟날낡낢남납낫났낭낮낯낱낳내낵낸낼냄냅냇냈냉냐냑냔냘냠냥너넉넋넌널넒넓넘넙넛넜넝넣네넥넨넬넴넵넷넸넹녀녁년녈념녑녔녕녘녜녠노녹논놀놂놈놉놋농높놓놔놘놜놨뇌뇐뇔뇜뇝뇟뇨뇩뇬뇰뇹뇻뇽누눅눈눋눌눔눕눗눙눠눴눼뉘뉜뉠뉨뉩뉴뉵뉼늄늅늉느늑는늘늙늚늠늡늣능늦늪늬늰늴니닉닌닐닒님닙닛닝닢다닥닦단닫달닭닮닯닳담답닷닸당닺닻닿대댁댄댈댐댑댓댔댕댜더덕덖던덛덜덞덟덤덥덧덩덫덮데덱덴델뎀뎁뎃뎄뎅뎌뎐뎔뎠뎡뎨뎬도독돈돋돌돎돐돔돕돗동돛돝돠돤돨돼됐되된될됨됩됫됴두둑둔둘둠둡둣둥둬뒀뒈뒝뒤뒨뒬뒵뒷뒹듀듄듈듐듕드득든듣들듦듬듭듯등듸디딕딘딛딜딤딥딧딨딩딪따딱딴딸땀땁땃땄땅땋때땍땐땔땜땝땟땠땡떠떡떤떨떪떫떰떱떳떴떵떻떼떽뗀뗄뗌뗍뗏뗐뗑뗘뗬또똑똔똘똥똬똴뙈뙤뙨뚜뚝뚠뚤뚫뚬뚱뛔뛰뛴뛸뜀뜁뜅뜨뜩뜬뜯뜰뜸뜹뜻띄띈띌띔띕띠띤띨띰띱띳띵라락란랄람랍랏랐랑랒랖랗래랙랜랠램랩랫랬랭랴략랸럇량러럭런럴럼럽럿렀렁렇레렉렌렐렘렙렛렝려력련렬렴렵렷렸령례롄롑롓로록론롤롬롭롯롱롸롼뢍뢨뢰뢴뢸룀룁룃룅료룐룔룝룟룡루룩룬룰룸룹룻룽뤄뤘뤠뤼뤽륀륄륌륏륑류륙륜률륨륩륫륭르륵른를름릅릇릉릊릍릎리릭린릴림립릿링마막만많맏말맑맒맘맙맛망맞맡맣매맥맨맬맴맵맷맸맹맺먀먁먈먕머먹먼멀멂멈멉멋멍멎멓메멕멘멜멤멥멧멨멩며멱면멸몃몄명몇몌모목몫몬몰몲몸몹못몽뫄뫈뫘뫙뫼묀묄묍묏묑묘묜묠묩묫무묵묶문묻물묽묾뭄뭅뭇뭉뭍뭏뭐뭔뭘뭡뭣뭬뮈뮌뮐뮤뮨뮬뮴뮷므믄믈믐믓미믹민믿밀밂밈밉밋밌밍및밑바박밖밗반받발밝밞밟밤밥밧방밭배백밴밸뱀뱁뱃뱄뱅뱉뱌뱍뱐뱝버벅번벋벌벎범법벗벙벚베벡벤벧벨벰벱벳벴벵벼벽변별볍볏볐병볕볘볜보복볶본볼봄봅봇봉봐봔봤봬뵀뵈뵉뵌뵐뵘뵙뵤뵨부북분붇불붉붊붐붑붓붕붙붚붜붤붰붸뷔뷕뷘뷜뷩뷰뷴뷸븀븃븅브븍븐블븜븝븟비빅빈빌빎빔빕빗';

var paddingCharacter = '흐';

function encode1(bytearray) {
  var len = bytearray.length;
  var a, b, c, d, e, result = [];
  for (var i = 0; i < len; ++i) {
    result.push(
      ksx1001_1028[(a = bytearray[i] & 255) << 2 | (b = bytearray[++i] & 255) >> 6],
      i < len ? ksx1001_1028[(b & 63) << 4 | (c = bytearray[++i] & 255) >> 4] : paddingCharacter,
      i < len ? ksx1001_1028[(c & 15) << 6 | (d = bytearray[++i] & 255) >> 2] : paddingCharacter,
      (d = d & 3, e = bytearray[++i] & 255, i) < len ? ksx1001_1028[d << 8 | e] : i === len ? ksx1001_1028[d | 1024] : paddingCharacter
    );
  }
  return result.join('');
};

function decode1(basehangulString) {
  var baseData = basehangulString.split('').map(function (character) { return ksx1001_1028.indexOf(character); });
  var len = baseData.length;
  var a, b, c, d, result = [];
  for (var i = 0; i < len; ++i) {
    a = baseData[i]; b = baseData[++i]; c = baseData[++i]; d = baseData[++i];
    result.push((a >> 2) & 255);
    if (b === -1) break;
    result.push((a & 3) << 6 | b >> 4);
    if (b === -1 || c === -1) break;
    result.push((b & 15) << 4 | c >> 6);
    if (c === -1 || d === -1) break;
    result.push((c & 63) << 2 | (d > 1023 ? d & 3: d >> 8));
    if (d > 1023) break;
    result.push(d & 255);
  }
  return result;
}

// https://stackoverflow.com/a/18729931

function toUTF8Array(str) {
  var utf8 = [];
  for (var i=0; i < str.length; i++) {
    var charcode = str.charCodeAt(i);
    if (charcode < 0x80) utf8.push(charcode);
    else if (charcode < 0x800) {
      utf8.push(0xc0 | (charcode >> 6), 
                0x80 | (charcode & 0x3f));
    }
    else if (charcode < 0xd800 || charcode >= 0xe000) {
      utf8.push(0xe0 | (charcode >> 12), 
                0x80 | ((charcode>>6) & 0x3f), 
                0x80 | (charcode & 0x3f));
    }
    // surrogate pair
    else {
      i++;
      // UTF-16 encodes 0x10000-0x10FFFF by
      // subtracting 0x10000 and splitting the
      // 20 bits of 0x0-0xFFFFF into two halves
      charcode = 0x10000 + (((charcode & 0x3ff)<<10)
                | (str.charCodeAt(i) & 0x3ff));
      utf8.push(0xf0 | (charcode >>18), 
                0x80 | ((charcode>>12) & 0x3f), 
                0x80 | ((charcode>>6) & 0x3f), 
                0x80 | (charcode & 0x3f));
    }
  }
  return utf8;
}

// http://www.onicos.com/staff/iz/amuse/javascript/expert/utf.txt

/* utf.js - UTF-8 <=> UTF-16 convertion
 *
 * Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
 * Version: 1.0
 * LastModified: Dec 25 1999
 * This library is free.  You can redistribute it and/or modify it.
 */

 function Utf8ArrayToStr(array) {
  var out, i, len, c;
  var char2, char3;

  out = "";
  len = array.length;
  i = 0;
  while (i < len) {
    c = array[i++];
    switch (c >> 4)
    { 
      case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
        // 0xxxxxxx
        out += String.fromCharCode(c);
        break;
      case 12: case 13:
        // 110x xxxx   10xx xxxx
        char2 = array[i++];
        out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
        break;
      case 14:
        // 1110 xxxx  10xx xxxx  10xx xxxx
        char2 = array[i++];
        char3 = array[i++];
        out += String.fromCharCode(((c & 0x0F) << 12) |
                                   ((char2 & 0x3F) << 6) |
                                   ((char3 & 0x3F) << 0));
        break;
    }
  }    
  return out;
}

// Custom

function handleConvert() {
  var encodeordecode = document.querySelector('input[name="encodeordecode"]:checked').value;
  var func = encodeordecode === 'encode' ? function(x) { return encode1(toUTF8Array(x)); } : function(x) { return Utf8ArrayToStr(decode1(x)); };
  outputarea.innerText = func(inputarea.value);
}
</script>
<style>
textarea {
  line-height: inherit;
  min-height: 8em;
  min-width: 100%;
  resize: vertical;
  max-width: 800px;
}

.pure-button {
  padding: 0.2em 1em;
}

.pure-form {
  text-align: center;
}

.pure-form .pure-checkbox, .pure-form .pure-radio {
  display: inline-block;
}

output {
  display: block;
  max-width: 800px;
  text-align: left;
  overflow-wrap: break-word;
}
</style>
</head>
<body>
  <h1>BaseHangul在线编解码器 Online BaseHangul Encoder And Decoder</h1>
  <form class="pure-form" onsubmit="handleConvert(); return false">
    <p>
      <textarea id="inputarea"></textarea>
    </p>
    <center><p>
      <label class="pure-radio"><input type="radio" name="encodeordecode" value="encode" checked="checked"> 编码 Encode</label>&nbsp;
      <label class="pure-radio"><input type="radio" name="encodeordecode" value="decode"> 解码 Decode</label>&nbsp;
      <input class="pure-button" type="submit" value="开始 Start">
    </p></center>
    <output id="outputarea"></output>
  </form>

  <h2>什么是谚文？ What is Hangul?</h2>
  <p>谚文是朝鲜民族所使用的表音文字系统，于1443年由朝鲜国王李祹创制，是朝鲜民族语言现行的正式文字。谚文由『字母』组合而成，一个谚文表示一个音节，进而推广为丰富的词汇。</p>
  <p>Hangul is the Korean writing system that consists of syllabic characters representing the sounds of the Korean language. It was created in the 15th century and is now the official script of Korea. Hangul is composed of individual characters called "jamo" that represent syllables and can be combined to form complex words.</p>
  <h2>什么是BaseHangul？ What is BaseHangul?</h2>
  <p>与Base64类似，BaseHangul也是一种二进制编码，特点是使用谚文表示二进制数据。由于大韩民国的KS C 5601标准是以10位为基准编制的，而当今主流的二进制计算机处理的基础是8位，『8』与『10』的最小公倍数是『40』，故而BaseHangul是以『每40位（5字节）的数据转化为4个谚文』运作的。大韩民国的KS C 5601字符编码标准收录有谚文2350个，BaseHangul以字典顺序选取了其中1028个使用。谚文『흐』超出该标准范围是为了用作填充字符。</p>
  <p>Similar to Base64, BaseHangul is a binary encoding that uses Hangul (Korean writing system) characters to represent binary data. It converts 5 bytes (40 bits) into 4 Hangul characters based on the KS C 5601 standard. The 40-bit conversion is chosen because it is the least common multiple of 8 and 10, which are the number of bits used to represent 1 character. 1028 Hangul characters out of 2350 in the standard are selected in dictionary order for the encoding. The character "흐" is outside of the selected range but used as a padding character.</p>
  <h2>什么是BaseHangul在线编解码器？ What is the Online BaseHangul Encoder and Decoder?</h2>
  <p><b>BaseHangul在线编解码器</b>是一款䏻快速高效地对BaseHangul数据编解码的先进工具。该工具基于JavaScript实现，䏻在您的浏览器中提供顺畅的用户体验。处理是在本地完成的，不会将任何数据传递过与第三方，您的信息将始终是隐秘而安全的。只需点一下，您就可以轻松地将文本转换为谚文字符组群，反之亦然。无论您是在BaseHangul或相关领域的专业人士，还是仅为了寻求方便编解码BaseHangul数据途径的爱好者，这个在线工具都是完美的解决方案。</p>
  <p>Online BaseHangul Encoder and Decoder is a cutting-edge tool designed for quick and efficient encoding and decoding of BaseHangul data. With its fast and reliable implementation in JavaScript, this tool provides a seamless user experience right in your web browser. The computation is done locally, ensuring that your information is kept secure and confidential at all times, as it does not transmit any data to any third-party servers. With just one click, you can easily convert text data into Hangul characters and vice versa, saving you time and effort. Whether you're a professional or simply looking for a convenient way to encode and decode BaseHangul data, this online tool is the perfect solution.</p>
  <h2>更多信息 More information</h2>
  <p><b>BaseHangul在线编解码器</b>基于BaseHangul 1.1编码标准的JavaScript项目——<a href="https://github.com/basehangul/basehangul-javascript">basehangul-javascript</a>。该项目提供了一个可靠而高效的编解码二进制数据为谚文的平台。</p>
  <p>The Online BaseHangul Encoder and Decoder is built upon the <a href="https://github.com/basehangul/basehangul-javascript">basehangul-javascript</a> project, which is a JavaScript implementation of the BaseHangul 1.1 encoding standard. The project provides a reliable and efficient platform for encoding and decoding binary data into Hangul characters.</p>
  <p>有关BaseHangul的更多内容（发展历史、其它实例项目等），请访问<a href="https://basehangul.github.io/">官方网站</a>。此外，该网站还提供了大量关于如何使用BaseHangul的要点，包括教程、示例和API。无论您是开发人员、研究人员还是只是想了解更多关于BaseHangul资讯的爱好者，官方网站都是一个极好的平台，提供了您初步了解所需的所有信息。</p>
  <p>For more information on BaseHangul, we encourage you to visit the <a href="https://basehangul.github.io/">official website</a>. Here, you will find detailed information about the encoding standard, including its history, development, and implementation. Additionally, the site provides a wealth of resources and information about how to use BaseHangul, including tutorials, examples, and APIs. Whether you're a developer, researcher, or simply interested in learning more about BaseHangul, the official website is an excellent resource that provides all the information you need to get started.</p>
  <h2>您的意见很重要！ Your voice matters!</h2>
  <p>如果您遇到任何问题或对<b>BaseHangul在线编解码器</b>有改进建议，您可以访问本项目的<a href="https://github.com/ayaka14732/basehangul-online">原始GitHub仓库</a>页面。该仓库由本工具的开发者<b>三日月绫香</b>维护，并为来访者提供了一个反馈问题、改进建议并为项目做出贡献的平台。无论您是专业的开发人员还是一般的爱好者，您都可以使<b>BaseHangul在线编解码器</b>向着更好的未来前进。</p>
  <p>If you encounter any issues or have suggestions for improvements to the Online BaseHangul Encoder and Decoder tool, you can visit the source code on <a href="https://github.com/ayaka14732/basehangul-online">GitHub</a>. This repository is maintained by the tool's developers and provides a platform for users to report issues, suggest improvements, and contribute to the project. Whether you're a developer or just a user, you can help make the Online BaseHangul Encoder and Decoder tool even better.</p>
</body>
</html>
